package com.itheima.reggie.exception;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

import static com.itheima.reggie.exception.BaseContext.getCurrentId;

@Component
public class MyMetaObjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        System.out.println("自动填充");
        metaObject.setValue("create_time",LocalDateTime.now());
        metaObject.setValue("update_time",LocalDateTime.now());
        metaObject.setValue("createUser",getCurrentId() );
        metaObject.setValue("updateUser",getCurrentId());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("update_time",LocalDateTime.now());
        metaObject.setValue("updateUser",getCurrentId());
    }
}
